﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using Model;

namespace DAL
{
    public class LevelRepository:ILevelRepository
    {
        //public static string connectionString = ConfigurationManager.ConnectionStrings["projectbConnection"].ToString();
        private SqlConnection conn;
        public LevelRepository(SqlConnection sqlconnnection)
        {
            this.conn = sqlconnnection;
        }
        public List<Model.Level> selectLevel()
        {
            DataSet ds = new DataSet();
            List<Model.Level> level = new List<Model.Level>();
          
                try
                {
                    conn.Open();
                    SqlCommand comm = new SqlCommand("select LevelName, LevelId from Level", conn);
                    SqlDataAdapter da = new SqlDataAdapter(comm);
                    da.Fill(ds, "Level");
                    //return ds;
                    foreach (DataRow row in ds.Tables[0].Rows)
                    {
                        Model.Level c = new Model.Level
                        {
                            LevelName = row[0].ToString(),
                            LevelId = Convert.ToInt32(row[1])
                        };
                        level.Add(c);

                    }
                    return level;
                }
                catch (SqlException e)
                {
                    throw new Exception(e.Message);
                }

            }

        }
    }

